﻿using HandyControl.Controls;
using Ping9719.WpfEx;
using SqlSugar.DistributedSystem.Snowflake;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BaseUi.Views.PlcView
{
    /// <summary>
    /// OutBoxTale.xaml 的交互逻辑
    /// </summary>
    public partial class OutBoxTaleView : UserControlBase
    {
        public OutBoxTaleView()
        {
            InitializeComponent();
        }

        private void loadFirst(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;
            Getnewbleder();
        }

        private void outboxButton_Click(object sender, RoutedEventArgs e)
        {
            Getnewbleder();
        }

        private void Getnewbleder()
        {
            var ioi = LocalStatic.Plc.Read<float>("1180");
            if (ioi.IsSucceed==false)
            {
                OutBox1g1.Text = "未接收";
            }
            else
            {
                OutBox1g1.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1208");
            if (ioi.IsSucceed == false)
            {
                OutBox1g2.Text = "未接收";
            }
            else
            {
                OutBox1g2.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1210");
            if (ioi.IsSucceed == false)
            {
                OutBox1g3.Text = "未接收";
            }
            else
            {
                OutBox1g3.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1212");
            if (ioi.IsSucceed == false)
            {
                OutBox1g4.Text = "未接收";
            }
            else
            {
                OutBox1g4.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1244");
            if (ioi.IsSucceed == false)
            {
                OutBox1g5.Text = "未接收";
            }
            else
            {
                OutBox1g5.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1236");
            if (ioi.IsSucceed == false)
            {
                OutBox1g6.Text = "未接收";
            }
            else
            {
                OutBox1g6.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1238");
            if (ioi.IsSucceed == false)
            {
                OutBox1g7.Text = "未接收";
            }
            else
            {
                OutBox1g7.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1174");
            if (ioi.IsSucceed == false)
            {
                OutBox2g1.Text = "未接收";
            }
            else
            {
                OutBox2g1.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1190");
            if (ioi.IsSucceed == false)
            {
                OutBox2g2.Text = "未接收";
            }
            else
            {
                OutBox2g2.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1224");
            if (ioi.IsSucceed == false)
            {
                OutBox2g3.Text = "未接收";
            }
            else
            {
                OutBox2g3.Text = ioi.Value.ToString();
            }
            //OutBox1g1.Text= LocalStatic.Plc.Read<float>("1180").Value.ToString();
            //OutBox1g2.Text = LocalStatic.Plc.Read<float>("1208").Value.ToString();
            //OutBox1g3.Text = LocalStatic.Plc.Read<float>("1210").Value.ToString();
            //OutBox1g4.Text = LocalStatic.Plc.Read<float>("1212").Value.ToString();
            //OutBox1g5.Text = LocalStatic.Plc.Read<float>("1244").Value.ToString();
            //OutBox1g6.Text = LocalStatic.Plc.Read<float>("1236").Value.ToString();
            //OutBox1g7.Text = LocalStatic.Plc.Read<float>("1238").Value.ToString();
            //OutBox2g1.Text = LocalStatic.Plc.Read<float>("1174").Value.ToString();
            //OutBox2g2.Text = LocalStatic.Plc.Read<float>("1190").Value.ToString();
            //OutBox2g3.Text = LocalStatic.Plc.Read<float>("1224").Value.ToString();
        }

        private void Label_OutBoxDoubleClick1g1(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox1g1.Text);
                var ioi = LocalStatic.Plc.Write<float>("1180", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick1g2(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox1g2.Text);
                var ioi = LocalStatic.Plc.Write<float>("1208", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick1g3(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox1g3.Text);
                var ioi = LocalStatic.Plc.Write<float>("1210", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick1g4(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox1g4.Text);
                var ioi = LocalStatic.Plc.Write<float>("1212", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick1g5(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox1g5.Text);
                var ioi = LocalStatic.Plc.Write<float>("1244", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick1g6(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox1g6.Text);
                var ioi = LocalStatic.Plc.Write<float>("1236", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick1g7(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox1g7.Text);
                var ioi = LocalStatic.Plc.Write<float>("1238", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick2g1(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox2g1.Text);
                var ioi = LocalStatic.Plc.Write<float>("1174", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick2g2(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox2g2.Text);
                var ioi = LocalStatic.Plc.Write<float>("1190", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void Label_OutBoxDoubleClick2g3(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(OutBox2g3.Text);
                var ioi = LocalStatic.Plc.Write<float>("1224", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
    }
}
